//
//  Macros.h
//  CloudAlbum
//
//  Created by WisdomsLab on 13-11-7.
//  Copyright (c) 2013年 Huanhao Tech. All rights reserved.
//

#ifndef Macros_h
#define Macros_h

//屏蔽GA版日志
#ifndef __OPTIMIZE__
#    define NSLog(...) NSLog(__VA_ARGS__)
#else
#    define NSLog(...) {}
#endif

//ARC兼容性
#if __has_feature(objc_arc)
#define PX_AUTORELEASE(expression) expression
#define PX_RELEASE(expression) expression
#define PX_RETAIN(expression) expression
#else
#define PX_AUTORELEASE(expression) [expression autorelease]
#define PX_RELEASE(expression) [expression release]
#define PX_RETAIN(expression) [expression retain]
#endif

#define IS_IPHONE5 ([[UIScreen mainScreen] bounds].size.height == 568) ? YES : NO)

#define IS_IOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 ? YES : NO)

#define IS_Pad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

//GCD
#define global_async(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define global_sync(block) dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)

#define main_async(block) dispatch_async(dispatch_get_main_queue(),block)
#define main_sync(block) dispatch_sync(dispatch_get_main_queue(),block)


//系统文件夹
#define DocumentsDirectory() [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0]

#define DocumentsSubDirectory(dir) [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:dir]

#define LibraryDirectory() [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask, YES) objectAtIndex:0]

#define LibrarySubDirectory(dir) [[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:dir]

#define CacheDirectory() [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]

#define CacheSubDirectory(dir) [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:dir]

#define TempDirectory() NSTemporaryDirectory()

#define TempSubDirectory(dir) [NSTemporaryDirectory() stringByAppendingPathComponent:dir]

//颜色
#define UIColorFromHex(hexValue) [UIColor \
colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0 \
green:((float)((hexValue & 0xFF00) >> 8))/255.0 \
blue:((float)(hexValue & 0xFF))/255.0 alpha:1.0]

#define RGBColorMake(_R_,_G_,_B_) [UIColor colorWithRed:(_R_)/255.0f green:(_G_)/255.0f blue:(_B_)/255.0f alpha:1]
#define RGBAColorMake(_R_,_G_,_B_,_A_) [UIColor colorWithRed:(_R_)/255.0f green:(_G_)/255.0f blue:(_B_)/255.0f alpha:(_A_)]

//单例
#define SINGLETON_FOR_CLASS(className) \
\
+ (className *)shared##className { \
static className *shared##className = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
shared##className = [[self alloc] init]; \
}); \
return shared##className; \
}

#define CHDelegate (AppDelegate *)[UIApplication sharedApplication].delegate
//主窗体
#define MAIN_WINDOW [[[UIApplication sharedApplication] delegate] window]
#define ROOT_CONTROLLER [MAIN_WINDOW rootViewController]
#define SCREEN_BOUNDS [[UIScreen mainScreen] bounds]

#define DEVICE_NAME [[UIDevice currentDevice] systemName]
#define OS_NAME [NSString stringWithFormat:@"%@%@", [[UIDevice currentDevice] systemName],[[UIDevice currentDevice] systemVersion]]

#define APP_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
#define APP_BUILD_VERSION   [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
#define APP_NAME   [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]
#define APP_REGION   [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDevelopmentRegion"]

#endif
